//
//  BRCustomView.m
//  Kexu
//
//  Created by IOS on 2023/7/19.
//

#import "BRCustomView.h"

@implementation BRCustomView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    self.backgroundColor = UIColorMakeWithRGBA(0, 185, 255, 0.2);
    self.layer.borderColor = kColorMainBorder.CGColor;
    self.layer.cornerRadius = 10;
    self.layer.masksToBounds = YES;
}


- (void)setBorderColor:(UIColor *)borderColor {
    _borderColor = borderColor;
    self.layer.borderColor = borderColor.CGColor;
}

- (void)setBorderWidth:(CGFloat)borderWidth {
    _borderWidth = borderWidth;
    self.layer.borderWidth = borderWidth;
}

- (void)setCornerRadiu:(CGFloat)cornerRadiu {
    _cornerRadiu = cornerRadiu;
    self.layer.cornerRadius = cornerRadiu;
}
@end
#pragma mark - //------------------------ --
@implementation BRImgLabelView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    [self addSubview:self.imgBg];
    [self.imgBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(14);
        make.left.offset(0);
        make.top.offset(0);
    }];
    [self.imgBg addSubview:self.img];
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    self.titleL.numberOfLines = 0;
    [self addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.img.mas_right).offset(6);
        make.right.offset(0);
        make.top.bottom.offset(0);
        make.height.mas_greaterThanOrEqualTo(14);
    }];
}

- (UIImageView *)img {
    if (_img == nil) {
        _img = [[UIImageView alloc] initWithImage:UIImageMake(@"order_coupon")];
    }
    return _img;
}

- (UIView *)imgBg {
    
    if (_imgBg == nil) {
        _imgBg = [[UIView alloc] init];
        _imgBg.backgroundColor = UIColor.clearColor;
    }
    return _imgBg;
}

- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:kColorTitle66B font:[UIFont fontM:14]];
    }
    
    return _titleL;
}

@end

@implementation BRRulesView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    QMUILabel *titleL = [BRToolsView br_label:Localized(@"order_pricePlan") textColor:kColorTitle font:[UIFont fontS:17]];
//    QMUILabel *titleL2 = [BRToolsView br_label:Localized(@"home_depositTCApply") textColor:kColorTitle font:[UIFont fontS:17]];
    self.textPlan = [BRToolsView br_label:@"--" textColor:kColorTitle66B font:[UIFont fontR:13]];
//    self.textTC = [BRToolsView br_label:@"--" textColor:kColorTitle66B font:[UIFont fontR:13]];
    self.textPlan.numberOfLines = 0;
//    self.textTC.numberOfLines = 0;
    
    [self addSubview:titleL];
//    [self addSubview:titleL2];
    [self addSubview:self.textPlan];
//    [self addSubview:self.textTC];
    CGFloat marginX = 0;
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginX);
        make.right.offset(-marginX);
        make.top.offset(0);
    }];
    [self.textPlan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginX);
        make.right.offset(-marginX);
        make.top.equalTo(titleL.mas_bottom).offset(4);
    }];
//    [titleL2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.offset(marginX);
//        make.right.offset(-marginX);
//        make.top.equalTo(self.textPlan.mas_bottom).offset(20);
//    }];
//    [self.textTC mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.offset(marginX);
//        make.right.offset(-marginX);
//        make.top.equalTo(titleL2.mas_bottom).offset(4);
//        make.bottom.offset(0);
//    }];
    
    BRRulesTCView *tcView = [[BRRulesTCView alloc] init];
    [self addSubview:tcView];
    [tcView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginX);
        make.right.offset(-marginX);
        make.top.equalTo(self.textPlan.mas_bottom).offset(20);
        make.bottom.offset(0);
    }];
}


@end

@implementation BRRulesTCView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    QMUILabel *titleL = [BRToolsView br_label:Localized(@"home_depositTCApply") textColor:kColorTitle font:[UIFont fontS:17]];
    _titleL = titleL;
    [self addSubview:titleL];
    
    self.textTC = [BRToolsView br_label:Localized(@"home_depositApplyRule") textColor:kColorTitle66B font:[UIFont fontR:13]];
    self.textTC.numberOfLines = 0;
    [self addSubview:self.textTC];
    CGFloat marginX = 0;
   
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginX);
        make.right.offset(-marginX);
        make.top.offset(0);
    }];
    [self.textTC mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginX);
        make.right.offset(-marginX);
        make.top.equalTo(titleL.mas_bottom).offset(4);
        make.bottom.offset(0);
    }];
}

@end

@implementation BRCouponsRuleView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    self.spacing = 4;
    self.axis = UILayoutConstraintAxisVertical;
    
    self.tcView = [[BRRulesTCView alloc] init];
    self.tcView.titleL.font = [UIFont fontM:12];
    self.tcView.textTC.font = [UIFont fontM:12];
    
    [self addArrangedSubview:self.tcView];
    
    self.locationView = [[BRRulesTCView alloc] init];
    self.locationView.titleL.font = [UIFont fontM:12];
    self.locationView.textTC.font = [UIFont fontM:12];
    
    [self addArrangedSubview:self.locationView];
    
    self.tcView.titleL.text = Localized(@"coupon_instructionText");
    self.locationView.titleL.text = Localized(@"coupon_availableLoc");
    self.tcView.textTC.text = @"--";
    self.locationView.textTC.text = @"--";
//    self.miniPayView = [[BRImgLabelView alloc] init];
//
//    [self.miniPayView.img mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.width.mas_equalTo(12);
//
//    }];
//    self.miniPayView.titleL.font = [UIFont fontR:12];
    
   
//    [self addArrangedSubview:self.miniPayView];
}

@end

#pragma mark - BRMTitle2View --
@implementation BRMTitle2View

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)titleClick:(UIControl *)btn {
    
    if (self.titleBtnClick) self.titleBtnClick(btn);
}


- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:UIColorMakeWithRGBA(136, 157, 187, 1) font:[UIFont br_fontM:10]];
        _titleL.textAlignment = NSTextAlignmentCenter;
    }
    return _titleL;
}

- (QMUILabel *)textL {
    if (_textL == nil) {
        _textL = [BRToolsView br_label:@"--" textColor:UIColorMakeWithRGBA(136, 157, 187, 1) font:[UIFont br_fontS:14]];
        _textL.textAlignment = NSTextAlignmentCenter;
    }
    return _textL;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleL.text = title;
}

- (void)setText:(NSString *)text {
    _text = text;
    self.textL.text = text;
}

- (void)setTitleColor:(UIColor *)titleColor {
    _titleColor = titleColor;
    self.titleL.textColor = titleColor;
}

- (void)setTextColor:(UIColor *)textColor {
    _textColor = textColor;
    self.textL.textColor = textColor;
}

- (void)setHasAttTitle:(BOOL)hasAttTitle {
    _hasAttTitle = hasAttTitle;
    
    if (!hasAttTitle) {
        self.textL.text = _title;
        return;
    }
    self.titleL.userInteractionEnabled = YES;
    self.titleBtn.hidden = NO;
    NSString *title = self.title;
//    // 设置虚线样式
    NSDictionary *attributes = @{
        NSUnderlineStyleAttributeName: @(NSUnderlineStylePatternDot | NSUnderlineStyleSingle), // 虚线样式
        NSUnderlineColorAttributeName: kColorTitle99B, // 虚线颜色
        
                                  };
    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:title attributes:attributes];

    self.titleL.attributedText = attributedText;

    [self.titleL sizeToFit];
}

#pragma mark - UI --
- (void)setUI {
   
    [self addSubview:self.titleL];
    [self addSubview:self.textL];
    
    [self.textL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(-4);
        make.height.mas_equalTo(16);
    }];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.equalTo(self.textL.mas_top).offset(0);
        make.top.offset(0);
    }];
    
    self.titleBtn = [[UIControl alloc] init];
    [self.titleL addSubview:self.titleBtn];
    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    [self.titleBtn addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
    self.titleBtn.hidden = YES;
}

@end

@implementation BRMCustomTitle2View



#pragma mark - UI --
- (void)setUI {
    [super setUI];
    
    [self addSubview:self.stackView];
    [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.top.offset(14);
        make.bottom.offset(-14);
    }];
}

- (void)br_updateMarginX:(CGFloat)x {
    [self.stackView mas_updateConstraints:^(MASConstraintMaker *make) {

        make.left.offset(x);
        make.right.offset(-x);
    }];
}

- (void)br_borderStyleDefault {
    self.backgroundColor = kUIColorMainTint;
    self.stackView.titleColor = kColorTitle;
    self.stackView.textColor = kColorTitle;
    self.stackView.titleL.font = [UIFont fontR:12];
    self.stackView.textL.font = [UIFont fontB:17];
//    self.borderWidth = 1;
    self.cornerRadiu = 10;
//    self.borderColor = UIColorMakeWithRGBA(255,255,255,0.4);;
    [self.stackView.titleL mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        
        make.top.offset(0);
    }];
    [self.stackView.textL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(24);
        make.bottom.offset(0);
    }];
}

- (void)br_leftAlignment {
    self.stackView.titleL.numberOfLines = 2;
    self.stackView.titleL.textAlignment = NSTextAlignmentLeft;
    self.stackView.textL.textAlignment = NSTextAlignmentLeft;
}


- (BRMTitle2View *)stackView {
    if (_stackView == nil) {
        _stackView = [[BRMTitle2View alloc] init];
        
        }
    
    return _stackView;
}

@end


@implementation BRImgListView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    self.line = [BRToolsView getLineView];
    
    [self addSubview:self.img];
    [self addSubview:self.imgRight];
    [self addSubview:self.titleL];
    [self addSubview:self.line];
    
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.top.offset(10);
        make.bottom.offset(-10);
        make.width.height.mas_equalTo(36);
    }];
    
    [self.imgRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-14);
        make.centerY.offset(0);
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(10);
    }];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(60);
        make.centerY.offset(0);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.left.offset(14);
        make.bottom.offset(0);
        make.height.mas_equalTo(0.5);
    }];
}



- (UIImageView *)img {
    
    if (_img == nil) {
        _img = [[UIImageView alloc] init];
    }
    return _img;
}

- (UIImageView *)imgRight {
    
    if (_imgRight == nil) {
        _imgRight = [[UIImageView alloc] init];
        _imgRight.image = UIImageMake(@"arrow_right_gray6");
    }
    return _imgRight;
}

- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont fontS:14]];
        _titleL.textAlignment = NSTextAlignmentCenter;
    }
    return _titleL;
}

@end

#pragma mark - --- --
@implementation BRStateView


- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)br_status:(NSInteger)status {
    
    self.title = [BRStringTools strOrderOfType:status];
    self.stateVColor = [BRStringTools colorOrderOfType:status];
}

- (void)br_statusByWithdrawalRecord:(NSInteger)status {
    
    self.title = [BRStringTools strWithdrawalRecordOfType:status];
    self.stateVColor = [BRStringTools colorWithdrawalRecordOfType:status];
}

#pragma mark - UI --
- (void)setUI {
//    self.backgroundColor = uicolor
    [self addSubview:self.stateView];
    [self addSubview:self.titleL];
    
    [self.stateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.width.height.mas_equalTo(6);
        make.left.offset(0);
    }];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.equalTo(self.stateView.mas_right).offset(6);
    }];

}

- (void)setStateVColor:(UIColor *)stateVColor {
    _stateVColor = stateVColor;
    self.stateView.backgroundColor = stateVColor;
}

- (UIView *)stateView {
    
    if (_stateView == nil) {
        _stateView = [[UIView alloc] init];
        _stateView.layer.cornerRadius = 3;
        _stateView.layer.masksToBounds = YES;
    }
    return _stateView;
}
- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont fontS:17]];
    }
    return _titleL;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleL.text = title;
}

@end

@implementation BRMStateV2View


- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)br_status:(NSInteger)status{
    
    self.title = [BRStringTools br_stationStateStr:status];
    self.stateVColor = [BRStringTools br_stationStateColor:status];;
}


#pragma mark - UI --
- (void)setUI {
    
    [self addSubview:self.stateBGView];
    [self addSubview:self.stateView];
    [self addSubview:self.titleL];
    
    [self.stateBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    
    [self.stateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.width.height.mas_equalTo(6);
        make.left.offset(10);
    }];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.offset(-10);
        make.left.equalTo(self.stateView.mas_right).offset(6);
    }];

}

- (void)setStateVColor:(UIColor *)stateVColor {
    _stateVColor = stateVColor;
    self.stateView.backgroundColor = stateVColor;
    self.stateBGView.backgroundColor = stateVColor;
}

- (UIView *)stateView {
    
    if (_stateView == nil) {
        _stateView = [[UIView alloc] init];
        _stateView.layer.cornerRadius = 3;
        _stateView.layer.masksToBounds = YES;
    }
    return _stateView;
}

- (UIView *)stateBGView {
    if (_stateBGView == nil) {
        _stateBGView = [[UIView alloc] init];
        _stateBGView.layer.cornerRadius = 13;
        _stateBGView.layer.masksToBounds = YES;
        _stateBGView.alpha = 0.14;
    }
    return _stateBGView;
}

- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont br_fontM:12]];
    }
    return _titleL;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleL.text = title;
}


@end

@implementation BRSlotsView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    self.layer.borderColor = kColorShadow(0.03).CGColor;
    self.layer.borderWidth = 1;
    self.layer.masksToBounds = YES;
    self.backgroundColor = kUIColorMainTint;
    
    
    self.stackTitles = [[BRStackTitleTextView alloc] init];
    self.stackTitles.spacing = 0;
    self.stackTitles.titleL.font = [UIFont fontS:20];
    self.stackTitles.textL.font = [UIFont fontR:10];
    self.stackTitles.titleColor = kColorMain;
    self.stackTitles.textColor = kColorMain;
    self.stackTitles.title = @"0";
    self.stackTitles.text = Localized(@"shop_slots");
    [self addSubview:self.stackTitles];
    [self.stackTitles mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.centerX.offset(0);
    }];
}

@end


@implementation BROtpView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI --
- (void)setUI {
    
    QMUILabel *addL = [BRToolsView br_label:@"+" textColor:kColorTitle font:[UIFont br_fontS:15]];
    [self addSubview:addL];
    [addL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.centerY.offset(0);
    }];
    
    [self addSubview:self.codeL];
    [self.codeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.equalTo(addL.mas_right).offset(0);
    }];
    
    UIImageView *img = [[UIImageView alloc] initWithImage:UIImageMake(@"arrow_triangle_Black8")];
    [self addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.equalTo(self.codeL.mas_right).offset(6);
        make.size.mas_equalTo(CGSizeMake(8, 5));
        make.right.offset(0);
    }];
}

- (QMUILabel *)codeL {
    
    if (_codeL == nil) {
        _codeL = [BRToolsView br_label:kCountryCode textColor:kColorTitle font:[UIFont br_fontS:15]];

    }
    return _codeL;
}

@end

@implementation BRMoreBtn

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
    _cornerRadius = cornerRadius;
    self.layer.cornerRadius = cornerRadius;
}

#pragma mark - UI --
- (void)setUI {
    
    self.backgroundColor = UIColorMakeWithRGBA(255,255,255,0.14);
    self.layer.borderColor = UIColorMakeWithHex(@"#889DBB").CGColor;
    self.layer.borderWidth = 1;
    self.layer.masksToBounds = YES;
    
    
    [self addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-24);
        make.centerY.offset(0);
    }];
    
    UIImageView *img = [[UIImageView alloc] initWithImage:UIImageMake(@"arrow_trangle_down8")];
    [self addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(8);
        make.right.offset(-16);
        make.centerY.offset(0);
    }];
}

- (QMUILabel *)titleL {
    
    if (_titleL == nil) {
        _titleL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont br_fontS:14]];
        _titleL.textAlignment = NSTextAlignmentLeft;
    }
    return _titleL;
}

@end
